package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.TestBlockInfo;
import com.siwei.mes.service.TestBlockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 压试块相关
 *
 * @Description: 压试块接口
 * @Version: 1.0
 * @author: chenmaolin
 * @date: 2024/1/1 01:02
 */
@Api(value = "压试块接口")
@RestController
@RequestMapping("testBlock")
public class TestBlockController {
    @Resource
    private TestBlockService testBlockService;

    @ApiOperation(value = "分页获取试验台账")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<TestBlockInfo, TestBlockInfo> query) {
        return Json.succ().data(testBlockService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取压试块详情")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(testBlockService.loadById(id));
    }

    @ApiOperation(value = "完成压试块")
    @GetMapping("finish")
    public Json finish(@RequestParam("id") Long id) {
        testBlockService.finish(id);
        return Json.succ();
    }

    @ApiOperation(value = "修改压试块信息")
    @PostMapping("update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) TestBlockInfo entity) {
        testBlockService.update(entity);
        return Json.succ();
    }

}
